#ifndef game_h
#define game_h

#include <position.h>
#include <move.h>

//forward declarations
struct game_history_entry_t;


typedef struct game_t
{
  position_t pos;
  int incheck;
  int len;
  int gamestart;
  struct game_history_entry_t* history;
  int history_capacity;
} game_t;


/*
 * Initialize the game structure g.
 *
 * Must be called before using any game_t object.  Return 1 in case of
 * success, 0 in case of error.
 */
int game_init(game_t* g);

/*
 * Copy the content of *src into *dst.
 *
 * Return 1 in case of success, 0 in case of error.
 */
int game_copy(const game_t* src, game_t* dst);

/*
 * Set the starting position for g.
 *
 * pos must be a legal position, otherwise an error will be raised
 * (and the game content remain unchanged).  Return 1 in case of
 * success, 0 in case of error.
 */
int game_set_start_position(game_t* g, const struct position_t* pos);

/*
 * Set the standard chess starting position.
 */
void game_set_init_position(game_t* g);

/*
 * Return the number of half moves played.
 *
 * Note that if the starting position has been specified with
 * game_set_start_position, the number of moves may be greater. This
 * function returns only the number of half moves played by calling
 * game_make_move on g.
 */
int game_length(const game_t* g);

/*
 * Return the list of moves played.
 *
 * Returns in buf up to the first buflen moves played. Returns the
 * number of moves actually stored in buf (the minumum between the
 * game length and buflen).
 */
int game_moves(const game_t* g, move_t* buf, int buflen);
int game_make_move(game_t* g, move_t m);
int game_undo_move(game_t* g);
const struct position_t* game_cur_position(const game_t* g);
void game_cleanup(game_t* g);
int game_repeated_position(const game_t* g);
move_t game_last_move(const game_t* g);
int game_last_capture(const game_t* g);


int game_in_check(const game_t* g);
int game_is_checkmate(const game_t* g);
int game_is_stalemate(const game_t* g);
int game_draw_by_material(const game_t* g);
int game_draw_by_repetition(const game_t* g);
int game_draw_by_50(const game_t* g);


int game_make_checked_move(game_t* g, move_t m);
int game_undo_checked_move(game_t* g);


#endif  // game_h
